$(function (){
    //加载默认隐藏展示页
     $(".show").hide()
    //单击后获取输入内容
    $(".btn").bind("click",function (){
        var text = $(".text").val();
        console.log(text)
        $.ajax({
            type: "post",
            url: "/nlp?action=wordParsing",
            data: {
                text: text
            },
            dataType: "json",
            success: function (data){
                console.log(data)
                //遍历items
                var len = data.items.length;
                console.log(len)
                var htmlStr = "";
                for (var i = 0; i < len; i++) {
                    htmlStr += "<div class=\"bottom_div\"><p class=\"left_p\">词:</p ><span class=\"right_span\">" + data.items[i].word + "</span></div>"
                    htmlStr += " <div class=\"bottom_div\"><p class=\"left_p\">词性:</p ><span class=\"right_span\">" + data.items[i].postag + "</span></div>"
                    htmlStr += " <div class=\"bottom_div\"><p class=\"left_p\">词的父节点ID:</p ><span class=\"right_span\">" + data.items[i].head + "</span></div>"
                    htmlStr += " <div class=\"bottom_div\"><p class=\"left_p\">词与父节点的依存关系:</p ><span class=\"right_span\">" + data.items[i].deprel + "</span></div>"
                }
                //拼接到页面上
                $(".show_result").html(htmlStr);
                $(".text").val("");
                console.log("成功")
                console.log(data)

            },
             error : function (err){
              console.log("失败")
             }
        })
        //单击后展示隐藏页面
        $(".show").show()
    })

})



